package arrAndstr;

public class T14 {

    public static void main(String[] args) {
        String[] strs = new String[]{"ab", "a"};

        System.out.println(longestCommonPrefix(strs));

    }

    public static String longestCommonPrefix(String[] strs) {
        StringBuffer sb = new StringBuffer("");
        String strFirst = strs[0];

        for(int i=0; i<strFirst.length(); i++) {
            char ch = strFirst.charAt(i);
            for(int j=1; j<strs.length; j++) {
                if(i >= strs[j].length() || strs[j].charAt(i) != ch) {
                    return sb.toString();
                }
            }
            sb.append(ch);
        }

        return sb.toString();
    }
}
